package com.example.yigoumall.service;

import com.example.yigoumall.entity.News;
import com.example.yigoumall.mapper.NewsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class NewsService {
    
    @Autowired
    private NewsMapper newsMapper;
    
    public List<News> findAll() {
        return newsMapper.findAll();
    }
    
    public News findById(Integer id) {
        return newsMapper.findById(id);
    }
    
    public List<News> searchByTitle(String title) {
        return newsMapper.findByTitle(title);
    }
    
    public News save(News news) {
        if (news.getId() == null) {
            newsMapper.insert(news);
        } else {
            newsMapper.update(news);
        }
        return news;
    }
    
    public void deleteById(Integer id) {
        newsMapper.deleteById(id);
    }
}